//
//  GYPriceScreenViewController.m
//  GoodLuck
//
//  Created by apple on 2018/3/15.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYPriceScreenViewController.h"
#import "GYSearchViewController.h"
#import "GYSystemMessageViewController.h"
#import "GYBasePopoverViewController.h"
#import "PopoverAnimation.h"
#import "GYStoreSearchMainViewController.h"
#import "GYShopingCartViewController.h"

@interface GYPriceScreenViewController ()<UISearchBarDelegate>

@property (weak, nonatomic) IBOutlet UITextField *minPriceTextFiled;
@property (weak, nonatomic) IBOutlet UITextField *maxPriceTextFiled;
@property (weak, nonatomic) IBOutlet UIButton *screenBtu;

/** 动画代理 */
@property (nonatomic, strong) PopoverAnimation *animationDelegate;
@end

@implementation GYPriceScreenViewController


- (IBAction)screenBtuClick:(UIButton *)sender {
    self.shopPriceScreenCallBack(self.minPriceTextFiled.text,self.maxPriceTextFiled.text);
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化
    [self setupUI];
}

- (void)setupUI {
    //1.设置搜索框
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    searchBar.delegate = self;
    searchBar.frame = CGRectMake(0, 0, 130, 40);
    searchBar.backgroundImage = [[UIImage alloc] init];
    UITextField *searchField = [searchBar valueForKey:@"searchField"];
    searchField.layer.borderColor = RGBColor(152, 152, 152).CGColor;
    searchBar.placeholder = @"请输入关键词";
    self.navigationItem.titleView = searchBar;
    
    //2.设置导航栏
    //UIBarButtonItem *cateItem = [UIBarButtonItem itemWithImage:@"stiore_categroy_b" tagret:self action:@selector(categoryBtuClick) button:nil];
    UIBarButtonItem *moreItem = [UIBarButtonItem itemWithImage:@"more_b" tagret:self action:@selector(moreBtuClick) button:nil];
    self.navigationItem.rightBarButtonItems = @[moreItem];
    
    //设置界面属性
    self.screenBtu.layer.cornerRadius = 4;
}

#pragma mark -- 按钮点击事件

//- (void)categoryBtuClick {
//    GYStoreSearchMainViewController *searchMainVC = [[GYStoreSearchMainViewController alloc] initWithNibName:@"GYStoreSearchMainViewController" bundle:nil];
//    searchMainVC.store_id = self.store_id;
//    [self.navigationController pushViewController:searchMainVC animated:YES];
//}

- (void)moreBtuClick {
    GYBasePopoverViewController *basePopoverVC = [[GYBasePopoverViewController alloc] initWithNibName:@"GYBasePopoverViewController" bundle:nil];
    __weak typeof(self) weakSelf = self;
    basePopoverVC.popoverViewSelectIndexCallBack = ^(NSInteger index) {
        switch (index) {
            case 0:
            {
                weakSelf.tabBarController.selectedIndex = 0;
                [weakSelf.tabBarController.tabBar setHidden:NO];
            }
                break;
                
            case 1:
            {
                GYSearchViewController *searchVC = [[GYSearchViewController alloc] init];
                [weakSelf.navigationController pushViewController:searchVC animated:YES];
            }
                break;
                
            case 2:
            {
                GYShopingCartViewController *shopingCartVC = [[GYShopingCartViewController alloc] initWithNibName:@"GYShopingCartViewController" bundle:nil];
                [weakSelf.navigationController pushViewController:shopingCartVC animated:YES];
            }
                break;
                
            case 3:
            {
                GYSystemMessageViewController *systemMessageVC = [[GYSystemMessageViewController alloc] initWithNibName:@"GYSystemMessageViewController" bundle:nil];
                
                [weakSelf.navigationController pushViewController:systemMessageVC animated:YES];
                
            }
                break;
                
            default:
                break;
        }
    };
    basePopoverVC.titles = @[@"首页",@"搜索",@"购物车",@"消息"];
    basePopoverVC.images = @[@"home_w",@"search_w",@"ff_icon3",@"message_w"];
    
    self.animationDelegate = [[PopoverAnimation alloc] init];
    self.animationDelegate.popoverFrame = CGRectMake(ScreenWidth-widthScale(130, iphone6_W)-5, 50, widthScale(130, iphone6_W), basePopoverVC.titles.count*50);
    basePopoverVC.transitioningDelegate = (id)weakSelf.animationDelegate;
    
    basePopoverVC.modalPresentationStyle = UIModalPresentationCustom;
    [self presentViewController:basePopoverVC animated:YES completion:nil];
}

#pragma mark -- UISearchBarDelegate

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    [searchBar resignFirstResponder];
    GYStoreSearchMainViewController *searchMainVC = [[GYStoreSearchMainViewController alloc] initWithNibName:@"GYStoreSearchMainViewController" bundle:nil];
    searchMainVC.store_id = self.store_id;
    [self.navigationController pushViewController:searchMainVC animated:YES];
    
}
@end
